5 * Split off from Article.php and Skin.php, 2003-12-22
14 include_once ( "SpecialValidate.php" ) ;
17 var $mArticle, $mTitle, $mSkin;
18 var $lastline, $lastdate;
20 function PageHistory( $article ) {
21 $this->mArticle
=& $article;
22 $this->mTitle
=& $article->mTitle
;
25 # This shares a lot of issues (and code) with Recent Changes
28 global $wgUser, $wgOut, $wgLang, $wgShowUpdatedMarker, $wgRequest,
29 $wgTitle, $wgUseValidation ;
31 # If page hasn't changed, client can cache this
33 if( $wgOut->checkLastModified( $this->mArticle
->getTimestamp() ) ){
34 # Client cache fresh and headers sent, nothing more to do.
37 $fname = 'PageHistory::history';
38 wfProfileIn( $fname );
40 $wgOut->setPageTitle( $this->mTitle
->getPRefixedText() );
41 $wgOut->setSubtitle( wfMsg( 'revhistory' ) );
42 $wgOut->setArticleFlag( false );
43 $wgOut->setArticleRelated( true );
44 $wgOut->setRobotpolicy( 'noindex,nofollow' );
46 $id = $this->mTitle
->getArticleID();
48 $wgOut->addHTML( wfMsg( 'nohistory' ) );
49 wfProfileOut( $fname );
53 $limit = $wgRequest->getInt('limit');
54 if (!$limit) $limit = 50;
55 $offset = $wgRequest->getText('offset');
56 if (!isset($offset) ||
!preg_match("/^[0-9]+$/", $offset)) $offset = 0;
58 /* Check one extra row to see whether we need to show 'next' and diff links */
59 $limitplus = $limit +
1;
61 $namespace = $this->mTitle
->getNamespace();
62 $title = $this->mTitle
->getText();
63 $uid = $wgUser->getID();
64 $db =& wfGetDB( DB_SLAVE
);
65 if ($uid && $wgShowUpdatedMarker && $wgUser->getOption( 'showupdated' ))
66 $notificationtimestamp = $db->selectField( 'watchlist',
67 'wl_notificationtimestamp',
68 array( 'wl_namespace' => $namespace, 'wl_title' => $this->mTitle
->getDBkey(), 'wl_user' => $uid ),
70 else $notificationtimestamp = false;
72 $use_index = $db->useIndexClause( 'page_timestamp' );
73 $revision = $db->tableName( 'revision' );
75 $limits = $offsets = "";
77 if ($wgRequest->getText("dir") == "prev")
80 list($dirs, $oper) = array("DESC", "<");
82 list($dirs, $oper) = array("ASC", ">");
86 $offsets .= " AND rev_timestamp $oper '$offset' ";
88 $limits .= " LIMIT $limitplus ";
90 $sql = "SELECT rev_id,rev_user," .
91 "rev_comment,rev_user_text,rev_timestamp,rev_minor_edit ".
92 "FROM $revision $use_index " .
93 "WHERE rev_page=$id " .
95 "ORDER BY rev_timestamp $dirs " .
97 $res = $db->query( $sql, $fname );
99 $revs = $db->numRows( $res );
101 if( $revs < $limitplus ) // the sql above tries to fetch one extra
102 $this->linesonpage
= $revs;
104 $this->linesonpage
= $revs - 1;
106 $atend = ($revs < $limitplus);
108 $this->mSkin
= $wgUser->getSkin();
112 while ($line = $db->fetchObject($res)) {
115 if ($dir) $pages = array_reverse($pages);
116 if (count($pages) > 1)
117 $lowts = $pages[count($pages) - 2]->rev_timestamp
;
119 $lowts = $pages[count($pages) - 1]->rev_timestamp
;
122 $prevurl = $wgTitle->escapeLocalURL("action=history&dir=prev&offset={$offset}&limit={$limit}");
123 $nexturl = $wgTitle->escapeLocalURL("action=history&offset={$lowts}&limit={$limit}");
125 foreach (array(20, 50, 100, 250, 500) as $num) {
126 $urls[] = "<a href=\"".$wgTitle->escapeLocalURL(
127 "action=history&offset={$offset}&limit={$num}")."\">".$wgLang->formatNum($num)."</a>";
129 $bits = implode($urls, ' | ');
130 $numbar = wfMsg("viewprevnext",
131 "<a href=\"$prevurl\">".wfMsg("prevn", $limit)."</a>",
132 "<a href=\"$nexturl\">".wfMsg("nextn", $limit)."</a>",
136 if($this->linesonpage
> 0) {
137 $submitpart1 = '<input class="historysubmit" type="submit" accesskey="'.wfMsg('accesskey-compareselectedversions').
138 '" title="'.wfMsg('tooltip-compareselectedversions').'" value="'.wfMsg('compareselectedversions').'"';
139 $this->submitbuttonhtml1
= $submitpart1 . ' />';
140 $this->submitbuttonhtml2
= $submitpart1 . ' id="historysubmit" />';
142 $s .= $this->beginHistoryList();
144 foreach($pages as $line) {
145 $s .= $this->historyLine(
146 $line->rev_timestamp
, $line->rev_user
,
147 $line->rev_user_text
, $namespace,
148 $title, $line->rev_id
,
149 $line->rev_comment
, ( $line->rev_minor_edit
> 0 ),
151 $notificationtimestamp,
152 ($counter == 1 && $offset == 0)
156 $s .= $this->endHistoryList( !$atend );
160 if ( isset ( $wgUseValidation ) && $wgUseValidation ) {
161 $s .= "<p>" . Validation
::link2statistics ( $this->mArticle
) . "</p>" ;
164 $wgOut->addHTML( $s );
165 wfProfileOut( $fname );
168 function beginHistoryList() {
170 $this->lastdate
= $this->lastline
= '';
171 $s = '<p>' . wfMsg( 'histlegend' ) . '</p>';
172 $s .= '<form action="' . $wgTitle->escapeLocalURL( '-' ) . '" method="get">';
173 $prefixedkey = htmlspecialchars($wgTitle->getPrefixedDbKey());
174 $s .= "<input type='hidden' name='title' value=\"{$prefixedkey}\" />\n";
175 $s .= !empty($this->submitbuttonhtml1
) ?
$this->submitbuttonhtml1
."\n":'';
176 $s .= '<ul id="pagehistory">';
180 function endHistoryList( $skip = false ) {
181 $last = wfMsg( 'last' );
183 $s = $skip ?
'' : preg_replace( "/!OLDID![0-9]+!/", $last, $this->lastline
);
185 $s .= !empty($this->submitbuttonhtml2
) ?
$this->submitbuttonhtml2
: '';
190 function historyLine( $ts, $u, $ut, $ns, $ttl, $oid, $c, $isminor, $counter = '', $notificationtimestamp = false, $latest = false ) {
191 global $wgLang, $wgContLang;
194 if( !isset( $message ) ) {
195 foreach( explode( ' ', 'cur last selectolderversionfordiff selectnewerversionfordiff minoreditletter' ) as $msg ) {
196 $message[$msg] = wfMsg( $msg );
200 if ( $oid && $this->lastline
) {
201 $ret = preg_replace( "/!OLDID!([0-9]+)!/", $this->mSkin
->makeKnownLinkObj(
202 $this->mTitle
, $message['last'], "diff=\\1&oldid={$oid}",'' ,'' ,' tabindex="'.$counter.'"' ), $this->lastline
);
206 $dt = $wgLang->timeanddate( $ts, true );
213 $link = $this->mSkin
->makeKnownLinkObj( $this->mTitle
, $dt, $q );
216 $contribsPage =& Title
::makeTitle( NS_SPECIAL
, 'Contributions' );
217 $ul = $this->mSkin
->makeKnownLinkObj( $contribsPage,
218 htmlspecialchars( $ut ), 'target=' . urlencode( $ut ) );
220 $userPage =& Title
::makeTitle( NS_USER
, $ut );
221 $ul = $this->mSkin
->makeLinkObj( $userPage , htmlspecialchars( $ut ) );
225 if ( $oid && !$latest ) {
226 $curlink = $this->mSkin
->makeKnownLinkObj( $this->mTitle
, $message['cur'],
227 'diff=0&oldid='.$oid );
229 $curlink = $message['cur'];
232 if( $this->linesonpage
> 1) {
233 # XXX: move title texts to javascript
235 if ( !$oid ||
$latest ) {
236 $arbitrary = '<input type="radio" style="visibility:hidden" name="oldid" value="'.$oid.'" title="'.$message['selectolderversionfordiff'].'" />';
237 $checkmark = ' checked="checked"';
239 if( $counter == 2 ) $checkmark = ' checked="checked"';
240 $arbitrary = '<input type="radio" name="oldid" value="'.$oid.'" title="'.$message['selectolderversionfordiff'].'"'.$checkmark.' />';
243 $arbitrary .= '<input type="radio" name="diff" value="'.$oid.'" title="'.$message['selectnewerversionfordiff'].'"'.$checkmark.' />';
245 $s .= "({$curlink}) (!OLDID!{$oid}!) $arbitrary {$link} <span class='user'>{$ul}</span>";
246 $s .= $isminor ?
' <span class="minor">'.$message['minoreditletter'].'</span>': '' ;
249 $s .= $this->mSkin
->commentBlock( $c, $this->mTitle
);
250 if ($notificationtimestamp && ($ts >= $notificationtimestamp)) {
251 $s .= wfMsg( 'updatedmarker' );
255 $this->lastline
= $s;